package com.rubiksillusions.examples;

public class StringPermutations {
	private int i = 0;
	
	public StringPermutations() {
		perm1("abcdefghilm");
	}
	
	public void perm1(String s) {
		perm1("", s);
	}
	
	private void perm1(String prefix, String s) {
		int N = s.length();
		if (N == 0) {
			printVoice(prefix);
		} else {
			for (int i = 0; i < N; i++) {
				perm1(prefix + s.charAt(i), s.substring(0, i) + s.substring(i+1, N));
			}
        }
    }
	
	private void printVoice(String output) {
		if (i % 1000000 == 0)
			System.out.println(i + ". " + output);
		i++;
	}
	
	public static void main(String[] args) {
		new StringPermutations();
	}
}
